home *** CD-ROM | disk | FTP | other *** search
/ Symantec Visual Cafe for Java 2.5 / symantec-visual-cafe-2.5-database-dev-edition.iso / Visual Cafe Pro v1.0 / TUTORIAL.BIN / TinyInt.class (.txt) < prev    next >
Encoding:
Java Class File  |  1997-01-30  |  3.9 KB  |  127 lines

  1. package symantec.itools.db.net;
  2.  
  3. import java.io.DataOutputStream;
  4. import java.io.IOException;
  5. import symjava.lang.Bignum;
  6. import symjava.sql.SQLException;
  7.  
  8. class TinyInt extends NumberField {
  9.    byte _iVal;
  10.  
  11.    int getType() {
  12.       return 86;
  13.    }
  14.  
  15.    void readData(ServerObject data) throws SQLException, IOException, ErrorException {
  16.       this._iVal = ((NetData)data).getByte();
  17.    }
  18.  
  19.    void writeData(DataOutputStream os) throws IOException {
  20.       NetData data = new NetData(this._iVal);
  21.       data.write(os);
  22.    }
  23.  
  24.    public String getString() throws SQLException {
  25.       return ((Field)this).isNull() ? null : String.valueOf(this._iVal);
  26.    }
  27.  
  28.    public boolean getBoolean() throws SQLException {
  29.       if (((Field)this).isNull()) {
  30.          return false;
  31.       } else {
  32.          return this._iVal != 0;
  33.       }
  34.    }
  35.  
  36.    public byte getByte() throws SQLException {
  37.       return ((Field)this).isNull() ? 0 : this._iVal;
  38.    }
  39.  
  40.    public short getShort() throws SQLException {
  41.       return ((Field)this).isNull() ? 0 : (short)this._iVal;
  42.    }
  43.  
  44.    public int getInt() throws SQLException {
  45.       return ((Field)this).isNull() ? 0 : this._iVal;
  46.    }
  47.  
  48.    public long getLong() throws SQLException {
  49.       return ((Field)this).isNull() ? 0L : (long)this._iVal;
  50.    }
  51.  
  52.    public float getFloat() throws SQLException {
  53.       return ((Field)this).isNull() ? 0.0F : (float)this._iVal;
  54.    }
  55.  
  56.    public double getDouble() throws SQLException {
  57.       return ((Field)this).isNull() ? (double)0.0F : (double)this._iVal;
  58.    }
  59.  
  60.    public Bignum getBignum(int scale) throws SQLException {
  61.       return ((Field)this).isNull() ? null : new Bignum(this._iVal, scale);
  62.    }
  63.  
  64.    public void setBoolean(boolean x) throws SQLException {
  65.       if (x) {
  66.          this._iVal = 1;
  67.       } else {
  68.          this._iVal = 0;
  69.       }
  70.  
  71.       super._null = false;
  72.    }
  73.  
  74.    public void setByte(byte x) throws SQLException {
  75.       this._iVal = x;
  76.       super._null = false;
  77.    }
  78.  
  79.    public void setShort(short x) throws SQLException {
  80.       this._iVal = (byte)x;
  81.       super._null = false;
  82.    }
  83.  
  84.    public void setInt(int x) throws SQLException {
  85.       this._iVal = (byte)x;
  86.       super._null = false;
  87.    }
  88.  
  89.    public void setLong(long x) throws SQLException {
  90.       this._iVal = (byte)((int)x);
  91.       super._null = false;
  92.    }
  93.  
  94.    public void setFloat(float x) throws SQLException {
  95.       this._iVal = (byte)((int)x);
  96.       super._null = false;
  97.    }
  98.  
  99.    public void setDouble(double x) throws SQLException {
  100.       this._iVal = (byte)((int)x);
  101.       super._null = false;
  102.    }
  103.  
  104.    public void setBignum(Bignum x) throws SQLException {
  105.       this._iVal = (byte)x.intValue();
  106.       super._null = false;
  107.    }
  108.  
  109.    public void setString(String x) throws SQLException {
  110.       Integer i = new Integer(x);
  111.       this._iVal = (byte)i;
  112.       super._null = false;
  113.    }
  114.  
  115.    public int getSQLType() {
  116.       return -6;
  117.    }
  118.  
  119.    public Object getObject() throws SQLException {
  120.       return new Integer(this._iVal);
  121.    }
  122.  
  123.    public void setObject(Object obj) throws SQLException {
  124.       this.setInt((Integer)obj);
  125.    }
  126. }
  127.